main: Make ostree --version output YAML (and add gitrev)
authorColin Walters <walters@verbum.org>
Fri, 17 Feb 2017 15:22:43 +0000 (10:22 -0500)
committerAtomic Bot <atomic-devel@projectatomic.io>
Wed, 22 Feb 2017 18:57:18 +0000 (18:57 +0000)
I learned today that `docker version` does this and I really like
the idea.  While we have the patient open, also add the gitrev
with code taken from https://github.com/projectatomic/rpm-ostree/pull/584

Closes: #691
Approved by: giuseppe

Makefile.am
configure.ac
src/ostree/ot-main.c
tests/basic-test.sh
tests/ci-install.sh
tests/libtest.sh
tests/test-libarchive.sh

index 31c412518b34d32b88daa56a8f6e1070db7e3d98..cc0e76f5fe4d777e96cbd88beba1f410746e73ce 100644 (file)
@@ -19,6 +19,8 @@ include Makefile-decls.am
 
 shortened_sysconfdir = $$(echo "$(sysconfdir)" | sed -e 's|^$(prefix)||' -e 's|^/||')
 
+OSTREE_GITREV=$(shell if command -v git >/dev/null 2>&1 && test -d $(srcdir)/.git; then git describe --abbrev=42 --tags --always HEAD; fi)
+
 ACLOCAL_AMFLAGS = -I buildutil -I libglnx ${ACLOCAL_FLAGS}
 AM_CPPFLAGS += -DDATADIR='"$(datadir)"' -DLIBEXECDIR='"$(libexecdir)"' \
        -DLOCALEDIR=\"$(datadir)/locale\" -DSYSCONFDIR=\"$(sysconfdir)\" \
@@ -26,6 +28,7 @@ AM_CPPFLAGS += -DDATADIR='"$(datadir)"' -DLIBEXECDIR='"$(libexecdir)"' \
        -DOSTREE_FEATURES='"$(OSTREE_FEATURES)"' \
        -DOSTREE_COMPILATION \
        -DG_LOG_DOMAIN=\"OSTree\" \
+  -DOSTREE_GITREV='"$(OSTREE_GITREV)"' \
        -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_40 -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_40 \
        -DSOUP_VERSION_MIN_REQUIRED=SOUP_VERSION_2_40 -DSOUP_VERSION_MAX_ALLOWED=SOUP_VERSION_2_48
 AM_CFLAGS += -std=gnu99 $(WARN_CFLAGS)
index c5940c9fe5c2f9c5b7689e107b869bafcdba8038..979d8ccb7ccabea85a24a5fd0103f876d4aeb599 100644 (file)
@@ -92,7 +92,7 @@ AS_IF([test x$with_curl != xno ], [
     with_soup_default=yes
 ], [with_soup_default=check])
 AM_CONDITIONAL(USE_CURL, test x$with_curl != xno)
-if test x$with_curl = xyes; then OSTREE_FEATURES="$OSTREE_FEATURES +libcurl"; fi
+if test x$with_curl = xyes; then OSTREE_FEATURES="$OSTREE_FEATURES libcurl"; fi
 
 dnl When bumping the libsoup-2.4 dependency, remember to bump
 dnl SOUP_VERSION_MIN_REQUIRED and SOUP_VERSION_MAX_ALLOWED in
@@ -131,7 +131,7 @@ AS_IF([test x$with_soup != xno], [
     with_soup=no
   ])
 ], [ with_soup=no ])
-if test x$with_soup != xno; then OSTREE_FEATURES="$OSTREE_FEATURES +libsoup"; fi
+if test x$with_soup != xno; then OSTREE_FEATURES="$OSTREE_FEATURES libsoup"; fi
 AM_CONDITIONAL(USE_LIBSOUP, test x$with_soup != xno)
 AM_CONDITIONAL(HAVE_LIBSOUP_CLIENT_CERTS, test x$have_libsoup_client_certs = xyes)
 
@@ -158,7 +158,7 @@ PKG_CHECK_MODULES(OT_DEP_GPGME, gpgme-pthread >= $LIBGPGME_DEPENDENCY, have_gpgm
 AS_IF([ test x$have_gpgme = xno ], [
    AC_MSG_ERROR([Need GPGME_PTHREAD version $LIBGPGME_DEPENDENCY or later])
 ])
-OSTREE_FEATURES="$OSTREE_FEATURES +gpgme"
+OSTREE_FEATURES="$OSTREE_FEATURES gpgme"
 
 LIBARCHIVE_DEPENDENCY="libarchive >= 2.8.0"
 # What's in RHEL7.2.
@@ -245,7 +245,7 @@ AS_IF([ test x$with_libarchive != xno ], [
        with_libarchive=no
     ])
 ], [ with_libarchive=no ])
-if test x$with_libarchive != xno; then OSTREE_FEATURES="$OSTREE_FEATURES +libarchive"; fi
+if test x$with_libarchive != xno; then OSTREE_FEATURES="$OSTREE_FEATURES libarchive"; fi
 AM_CONDITIONAL(USE_LIBARCHIVE, test $with_libarchive != no)
 
 dnl This is what is in RHEL7 anyways
@@ -270,7 +270,7 @@ AS_IF([ test x$with_selinux != xno ], [
        with_selinux=no
     ])
 ], [ with_selinux=no ])
-if test x$with_selinux != xno; then OSTREE_FEATURES="$OSTREE_FEATURES +selinux"; fi
+if test x$with_selinux != xno; then OSTREE_FEATURES="$OSTREE_FEATURES selinux"; fi
 AM_CONDITIONAL(USE_SELINUX, test $with_selinux != no)
 
 AC_ARG_WITH(smack,
@@ -303,7 +303,7 @@ AS_IF([ test x$with_libmount != xno ], [
        with_libmount=no
     ])
 ], [ with_libmount=no ])
-if test x$with_libmount != xno; then OSTREE_FEATURES="$OSTREE_FEATURES +libmount"; fi
+if test x$with_libmount != xno; then OSTREE_FEATURES="$OSTREE_FEATURES libmount"; fi
 AM_CONDITIONAL(USE_LIBMOUNT, test $with_libmount != no)
 
 # Enabled by default because I think people should use it.
index fb782275a9558a53dfbc0f78268f55a58aa08def..c6a2b6dd28faa110ec08c0dfbd5db50405c114a8 100644 (file)
@@ -241,7 +241,16 @@ ostree_option_context_parse (GOptionContext *context,
 
   if (opt_version)
     {
-      g_print ("%s\n  %s\n", PACKAGE_STRING, OSTREE_FEATURES);
+      /* This should now be YAML, like `docker version`, so it's both nice to read
+       * possible to parse */
+      g_auto(GStrv) features = g_strsplit (OSTREE_FEATURES, " ", -1);
+      g_print ("%s:\n", PACKAGE_NAME);
+      g_print (" Version: %s\n", PACKAGE_VERSION);
+      if (strlen (OSTREE_GITREV) > 0)
+        g_print (" Git: %s\n", OSTREE_GITREV);
+      g_print (" Features:\n");
+      for (char **iter = features; iter && *iter; iter++)
+        g_print ("  - %s\n", *iter);
       exit (EXIT_SUCCESS);
     }
 
index d930813823bc33061cd75a7d5b835f81c07cb386..2698279631eb699cfe434208df72e00e33920f48 100644 (file)
 
 set -euo pipefail
 
-echo "1..61"
+echo "1..62"
+
+$CMD_PREFIX ostree --version > version.yaml
+python -c 'import yaml; yaml.safe_load(open("version.yaml"))'
+echo "ok yaml version"
 
 $OSTREE checkout test2 checkout-test2
 echo "ok checkout"
index 92f802d90632b3f6e127b14ae2ffe880dd04c384..d927d962b5c68b0fc690c96443198e746af1bc15 100755 (executable)
@@ -110,6 +110,7 @@ case "$ci_distro" in
             libcurl4-openssl-dev \
             procps \
             zlib1g-dev \
+            python-yaml \
             ${NULL}
 
         if [ "$ci_in_docker" = yes ]; then
index 541082686b8797865b21dae5a4269b0499829238..0126827e02424ef6440f9e0b07fed453f3a39fa2 100755 (executable)
@@ -538,7 +538,10 @@ skip_without_fuse () {
 }
 
 has_gpgme () {
-    ${CMD_PREFIX} ostree --version | grep -q -e '\+gpgme'
+    ${CMD_PREFIX} ostree --version > version.txt
+    assert_file_has_content version.txt '- gpgme'
+    rm -f version.txt
+    true
 }
 
 libtest_cleanup_gpg () {
index 0c579459526129813252788314b18ceefbfbdc21..6540b94b6715b8b8cc82099e0bfd7932acf29b19 100755 (executable)
@@ -19,7 +19,7 @@
 
 set -euo pipefail
 
-if ! ostree --version | grep -q -e '\+libarchive'; then
+if ! ostree --version | grep -q -e 'libarchive'; then
     echo "1..0 #SKIP no libarchive support compiled in"
     exit 0
 fi